import express from 'express'
import cors from 'cors'
import { config } from './config/env.js'
import { emotionRouter } from './routes/emotion.js'
import { imageRouter } from './routes/image.js'
import { errorMiddleware } from './middleware/error.js'

const app = express()

// Middleware
app.use(cors())
app.use(express.json())

// Routes
app.use('/api/emotion', emotionRouter)
app.use('/api/image', imageRouter)

// Health check
app.get('/health', (_req, res) => {
  res.json({ status: 'ok', timestamp: new Date().toISOString() })
})

// Error handling
app.use(errorMiddleware)

app.listen(config.port, () => {
  console.log(`Server running on port ${config.port}`)
})

export { app }
